package cn.stronglink.asset.module.basicdata.datacenter.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.plugins.Page;
import cn.stronglink.asset.model.DataCenter;
import cn.stronglink.asset.module.basicdata.datacenter.service.DataCenterService;
import cn.stronglink.suite.core.base.AbstractController;
import cn.stronglink.suite.core.log.annotation.OperateLog;
import cn.stronglink.suite.core.log.annotation.OperateLog.OpType;

@Controller
@RequestMapping(value = "basic/dataCenter")
public class DataCenterController extends AbstractController {

	@Autowired
	private DataCenterService dataCenterService;

	@RequestMapping(value = "queryList")
	public ResponseEntity<ModelMap> queryList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Map<String, Object> params) {		
		@SuppressWarnings("unchecked")
		Page<DataCenter> page = (Page<DataCenter>) super.getPage(params);
		Page<DataCenter> data = dataCenterService.queryDataCenter(page, params);
		return setSuccessModelMap(modelMap, data);
	}
	
	@RequestMapping(value = "queryAll")
	public ResponseEntity<ModelMap> queryAll(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response) {		
		List<DataCenter> data = dataCenterService.queryAll();
		return setSuccessModelMap(modelMap, data);
	}
	
	@OperateLog(module = "数据中心管理",desc="添加数据中心", type = OpType.ADD)
	@RequestMapping(value = "create")
	public ResponseEntity<ModelMap> create(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody DataCenter dataCenter) {
		dataCenterService.insertDataCenter(dataCenter);
		return setSuccessModelMap(modelMap, null);
	}
	
	@OperateLog(module = "数据中心管理",desc="编辑数据中心", type = OpType.UPDATE)
	@RequestMapping(value = "edit")
	public ResponseEntity<ModelMap> edit(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody DataCenter dataCenter) {
		dataCenterService.insertDataCenter(dataCenter);
		return setSuccessModelMap(modelMap, null);
	}
	
	@OperateLog(module = "数据中心管理",desc="删除数据中心", type = OpType.DEL)
	@RequestMapping(value = "remove")
	public ResponseEntity<ModelMap> remove(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Long id) {
		dataCenterService.removeDataCenter(id);
		return setSuccessModelMap(modelMap, null);
	}

}
